function signal = sinu_generator(config)
% freqs, gains, noisePower, fs, numSamples
% 检查输入参数的有效性
if length(config.freqs) ~= length(config.gains)
    error('频率和增益的长度必须相同');
end

% 初始化时间向量
t = (0:config.numSamples - 1)' / config.fs;

% 初始化信号
signal = zeros(config.numSamples, 1);

% 生成多个复正弦信号并叠加
for i = 1:length(config.freqs)
    signal = signal + config.gains(i) * exp(1j * 2 * pi * config.freqs(i) * t);
end

% 添加噪声
noiseStd = sqrt(config.noisePower);
noise = noiseStd * (1+1j) / sqrt(2) * randn(config.numSamples, 1);
signal = signal + noise;
end

% fig = figure('Visible','off');
% f = (-N/2:N/2 - 1) * fs / N;
% signal_fft = fftshift(fft(signal));
% plot(f, abs(signal_fft));
% grid on;
% exportgraphics(fig,'test.jpg');
% close(fig);